<?php

/**
 * AuthController
 * 
 * @author Maodo DIOP <dmaodo@gmail.com>
 * @version 
 */


class Admin_ProprietaireController extends Zend_Controller_Action {
	
	public function indexAction() {
		$this->_helper->viewRenderer->setNoRender();
		$this->_helper->getHelper('layout')->disableLayout();
		//$this->view->title = "Supprimer Espece";
		//$this->view->headTitle($this->view->title);
		$proprio = new Admin_Model_DbTable_Proprietaire();
		$res = $proprio->getAllProprio();
		$resultat = Zend_Json :: encode($res);
		$this->_response->setHeader('Content-Type', 'text/x-json');
		$this->_response->setBody($resultat);
	}
	
	
	public function getgmvAction() {
		$this->_helper->viewRenderer->setNoRender();
		$this->_helper->getHelper('layout')->disableLayout();
		//$this->view->title = "Supprimer Espece";
		//$this->view->headTitle($this->view->title);
		$idproprio = $this->_request->getParam('id', 0);
		$proprio = new Admin_Model_DbTable_Proprietaire();
		$res = $proprio->getProprioMatricegmv($idproprio);
		$resultat = Zend_Json :: encode($res);
		$this->_response->setHeader('Content-Type', 'text/x-json');
		$this->_response->setBody($resultat);
	}
	
	
	public function getbrAction() {
		$this->_helper->viewRenderer->setNoRender();
		$this->_helper->getHelper('layout')->disableLayout();
		//$this->view->title = "Supprimer Espece";
		//$this->view->headTitle($this->view->title);
		$idproprio = $this->_request->getParam('id', 0);
		$proprio = new Admin_Model_DbTable_Proprietaire();
		$res = $proprio->getProprioMatricebr($idproprio);
		$resultat = Zend_Json :: encode($res);
		$this->_response->setHeader('Content-Type', 'text/x-json');
		$this->_response->setBody($resultat);
	}
	public function addAction() {
		$this->view->title = "Ajouter Point GMV";
		$this->view->headTitle($this->view->title);
		
		if ($this->getRequest()->isPost()) {
			$latitude = stripslashes($this->_request->getPost('latitude'));
			$longitude = stripslashes($this->_request->getPost('longitude'));
			$bassin = 1;
			$idpointbassin_pred = stripslashes($this->_request->getPost('idpointbassin_pred'));
			$pointbassin = new Admin_Model_DbTable_Pointbassin();
			$pointbassin->addPointbassin($latitude,$longitude,$bassin,$idpointbassin_pred);                
			$this->_helper->redirector('index');
		}
		
	}
	
	public function editAction() {
		$form = new Admin_Form_Pointbassin() ;
		$form->submit->setLabel('Enregistrer');
		$this->view->form = $form;
		if ($this->getRequest()->isPost()) {
			$formData = $this->getRequest()->getPost();
			if ($form->isValid($formData)) {            	
				$idpointbassin = (int)$this->_getParam('idpointbassin');;             
				$latitude = $form->getValue('latitude');
				$longitude = $form->getValue('longitude');
				$bassin = $form->getValue('bassin');
				$pointbassin_idpointbassin_pred = $form->getValue('$pointbassin_idpointbassin_pred');          
				
				$pointbassin = new Admin_Model_DbTable_Pointbassin();
				$pointbassin->updatePointbassin($idpointbassin, $latitude, $longitude, $bassin, $pointbassin_idpointbassin_pred); 
				$res = array(); 
				$res = $pointbassin->getPointbassin($idpointbassin);        
				$this->_redirect('/admin/pointbassin/index');
			} else {
				$form->populate($formData);
			}
		} else {
			//Si le formulaire n'est pas encore post�
			//Recuperer la valeur de l'objet � editer
			$idpointbassin = $this->_request->getParam('idpointbassin', 0);
			if ($idpointbassin > 0) {
				$pointbassin = new Admin_Model_DbTable_Pointbassin();
				$form->populate($pointbassin->getPointbassin($idpointbassin));
			}
		} 
	}
	
	
	public function deleteAction() {
		$this->_helper->viewRenderer->setNoRender();
		$this->_helper->getHelper('layout')->disableLayout();
		
		$idpointbassin = $this->_getParam('idpointbassin', 0);
		$pointbassin = new Admin_Model_DbTable_Pointbassin();
		$pointbassin->deletePointbassin($idpointbassin);
		$this->_redirect('/admin/pointbassin/index');
	}
	
	public function allProprioAction() {
		$this->_helper->viewRenderer->setNoRender();
		$this->_helper->getHelper('layout')->disableLayout();
		$proprio = new Admin_Model_DbTable_Proprietaire();
		$res = $proprio->getAllProprio();
		$resultat = Zend_Json :: encode($res);
		$this->_response->setHeader('Content-Type', 'text/x-json');
		$this->_response->setBody($resultat);
	}
}

